package models

import (
	"github.com/cy77cc/hioshop/global"
)

type Shipper struct {
	Model
	Name         string `json:"name" gorm:"type:varchar(20);default:''"`
	Code         string `json:"code" gorm:"type:varchar(10);default:''"`
	SortOrder    int    `json:"sort_order" gorm:"type:int;default:10"`
	MonthCode    string `json:"month_code" gorm:"type:varchar(100)"`
	CustomerName string `json:"customer_name" gorm:"type:varchar(100)"`
	Enabled      int8   `json:"enabled" gorm:"type:tinyint;default:0"`
}

func (shipper *Shipper) GetShipperNameByCode() (err error) {
	err = global.DB.Model(&shipper).Select("name").Where("code = ?", shipper.Code).Find(&shipper).Error
	return
}

func (shipper *Shipper) GetShipperCodeById() (err error) {
	err = global.DB.Model(&shipper).Select("code").Where("id = ?", shipper.ID).Find(&shipper).Error
	return
}
